<template>
    <div class="productProNew">
        <div class="title"><h1><span>编辑行程</span></h1></div>
        <form name="基本信息" class="basicInfor">
            <h1 class="hide">行程名称(必填)</h1>
            <div class="form-group required">
                <label :for="'strokeName'+$attrs.text">行程名称：</label>
                <input autocomplete="off" type="text" class="form-control proName " :id="'strokeName'+$attrs.text" placeholder="请输入行程名称" required v-model="journey.title" >
            </div>

            <h1 class="hide">导游电话(必填)</h1>
            <div class="form-group wu required">
                <label :for="'phone'+$attrs.text">导游电话：</label>
                <input autocomplete="off" type="text" class="form-control proName" :id="'phone'+$attrs.text" placeholder="请输入导游电话" required v-model="journey.managePhone">
            </div>
            <div class="form-group wu required">
              <label :for="'lxMobile'+$attrs.text">旅行社电话：</label>
              <input autocomplete="off" type="text" class="form-control proName" :id="'lxMobile'+$attrs.text" placeholder="请输入旅行社电话" required v-model="lxMobile">
            </div>

            <!--<h1 class="hide">出发地（必填）</h1>-->
            <!--<div class="form-group departure required clearfix">-->
                <!--<label>出发地：</label>-->
                <!--<span class="site-p">{{startCity}}</span>-->
            <!--</div>-->

            <!--<h1 class="hide">目的地（必填）</h1>-->
            <!--<div class="form-group destination required clearfix">-->
                <!--<label>目的地：</label>-->
                <!--<span class="site-p">{{destiCity}}</span>-->
            <!--</div>-->

            <!--<h1 class="hide">出发日期（必填）</h1>-->
            <!--<div class="form-group required clearfix">-->
                <!--<label :for="'schduleDateStart'+$attrs.text">出发日期：</label>-->
                <!--<span class="site-p">{{setoffDate}}</span>-->
                <!--&lt;!&ndash;<input autocomplete="off" class="form-control ipt-datepicker adultPrice setoff" type="text" :id="'schduleDateStart'+$attrs.text" placeholder="起始时间" v-model="setoffDate">&ndash;&gt;-->
            <!--</div>-->

            <!--<h1 class="hide">游玩天数（必填）</h1>-->
            <!--<div class="form-group required clearfix">-->
                <!--<label :for="'strokeDay'+$attrs.text">游玩天数：</label>-->
                <!--<span class="site-p">{{journey.coDay}}</span>-->
                <!--&lt;!&ndash;<input autocomplete="off" type="text" class="form-control adultPrice" :id="'strokeDay'+$attrs.text" placeholder="" required v-model="journey.coDay">&ndash;&gt;-->
            <!--</div>-->
            <button type="button" class="btn btn-info confirmBtn" @click="submitPro()">确定</button>
        </form>
    </div>
</template>
<script>
    import Site from '@/components/public/site'
    export default{
        data(){
            return{
                Http:'',// 接口
                setoffDate:'',//出发日期
                startCity:'',
                destiCity:'',
                journey: {},
                lxMobile: ''
            }
        },
        computed:{
            BaseView(){
                return this.$store.state.interface.xchBaseView;
            },
            setXchBase(){
                return this.$store.state.interface.setXchBase;
            }
            // AreaList(){ // 地区
            //     return this.$store.state.interface.areaList;
            // },
        },
        components:{
            Site
        },
        methods:{
            // colorChange(event){
            //     event.target.style.color = '#7f889c';
            // },
            // // 出发
            // deparTure: function(msg,path){
            //     this.journey.startCity=msg;
            //     this.journey.startPath=path;
            // },
            // // 目标
            // desTination: function(msg,path){
            //     this.journey.destiCity=msg;
            //     this.journey.destiPath=path;
            // },
            // ContactPhone(item,event){ //判断手机正确格式
            //     var pattern = /^1[35789]\\d{9}$/;
            //     if(item.replace(/(^s*)|(s*$)/g, "") == 0){
            //         event.target.value='';
            //         return;
            //     }else if(!pattern.test(item)){
            //         layer.msg('请填写正确的手机号!');
            //     }
            // },
            submitPro(){ //提交判断是否信息完整
                let self = this;
                let isMobile = /^(13|14|15|17|18)\d{9}$/;
                if (self.journey.title === '') {
                  layer.msg('请填写行程名称');
                  return false
                }
                if (self.journey.managePhone === '') {
                  layer.msg('请填写导游电话');
                  return false
                }
                if (!isMobile.test(self.journey.managePhone)) {
                  layer.msg('请填写11位有效手机号');
                  return false
                }
                if (self.lxMobile === '') {
                  layer.msg('请填写旅行社电话');
                  return false
                }
                let formData =new FormData();
                formData.append('xid', self.journey.xid);
                formData.append('title', self.journey.title);
                formData.append('managePhone', self.journey.managePhone);
                formData.append('lxMobile', self.lxMobile);
                self.$ajax.post(self.Http,formData).then(function(res) {
                  console.log(res.data)
                  // if(res.data.code == '10000' ){
                  //   layer.msg('修改成功!');
                  // }else if(res.data.code == '14013' ){
                  //   layer.msg('修改失败,管理员电话为未注册号码!');
                  // }else{
                  //   self.codes(res.data.code);
                  //   layer.msg('修改失败!');
                  // }
                },function(res) {
                  layer.msg('服务器错误!');
                });
            },
            // shijianadd0(m){
            //     return m<10?'0'+m:m
            // },
            // shijian(shijianchuo){
            //     //shijianchuo是整数，否则要parseInt转换
            //     var time = new Date(parseInt(shijianchuo));
            //     var y = time.getFullYear();
            //     var m = time.getMonth()+1;
            //     var d = time.getDate();
            //     var h = time.getHours();
            //     var mm = time.getMinutes();
            //     var s = time.getSeconds();
            //     return y+'-'+this.shijianadd0(m)+'-'+this.shijianadd0(d);
            // },
        },
        beforeMount(){
            let self = this;
            let url = self.setXchBase;
            let sessionId = JSON.parse(sessionStorage.getItem('customer')).sid;
            self.Http = `${url}?sid=${sessionId}`; // 基础信息
            let baseView = `${self.BaseView}?sid=${sessionId}`; // 基础信息获取
            // let arealistUrl = self.AreaList+'?sid='+sessionId; // 地址
            self.$ajax.post(`${baseView}&xid=${self.$attrs.proid}`).then(function(res) {
              if(res.data.code === '10000' ){
                let ShowList= res.data.result;
                for(let i in ShowList){
                  self.journey = ShowList[i];
                };
                // var StartDate=self.journey.startDate;
                // self.setoffDate=self.shijian(StartDate);
                // 出发地
                // self.$ajax.post(arealistUrl+'&path='+self.journey.startPath).then(function(res3){
                //     var areaList= res3.data.result;
                //     var arealistZhou;
                //     for(var i in areaList){
                //         arealistZhou = areaList[i];
                //     };
                //     self.startCity=arealistZhou[0].sitePath;
                //     if(self.startCity.indexOf(self.journey.startCity)<0){
                //         self.startCity=self.startCity+self.journey.startCity+','
                //     }
                // });
                // // 目的地
                // self.$ajax.post(arealistUrl+'&path='+self.journey.destiPath).then(function(res4){
                //     var areaList= res4.data.result;
                //     var arealistZhou;
                //     for(var i in areaList){
                //         arealistZhou = areaList[i];
                //     };
                //     self.destiCity=arealistZhou[0].sitePath;
                //     if(self.destiCity.indexOf(self.journey.destiCity)<0){
                //         self.destiCity=self.destiCity+self.journey.destiCity+','
                //     }
                // });
              }else{
                self.codes(res.data.code);
                layer.msg('加载失败!');
              }
            },function(res) {
              layer.msg('服务器错误！');
            });
        },
        mounted(){
            // var self = this;
            // // 出发日期
            // $("#schduleDateStart"+this.$attrs.text).datepicker({
            //         showAnim: 'fadeIn',
            //         minDate: '-1y',
            //         maxDate: "+1y",
            //         defaultDate : +1,
            //         duration : 'fast',
            //         firstDay : 1 ,
            //         nextText : '下一月',
            //         prevText : '上一月',
            //         showButtonPanel: true,
            //         currentText : '今天',
            //         gotoCurrent : false,
            //         onSelect: function (dateText, inst) {
            //             // self.start = Number(dateText.split('-').join(''));//将字符串转换为number
            //             self.startDate = dateText;
            //             self.journey.startDate= Date.UTC(inst.currentYear, inst.currentMonth, inst.currentDay);
            //         },
            //
            // });
        }
    }
</script>
<style lang="scss" scoped>
    .basicInfor{
        form{
            display:block;
        }
        .title{
            color:#4e5e7e;
        }
    }
    .form-group .form-control.proName{width: 50%;}
</style>
